﻿using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebserviceClient
{
    public partial class WebFormClient : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
           

        }

        protected void button1_Click(object sender, EventArgs e)
        {
            ServiceReference1.WebService1SoapClient testService = new ServiceReference1.WebService1SoapClient();
            string result = testService.HelloWorld();
            textbox1.Text = result;
        }

        protected void button2_Click(object sender, EventArgs e)
        {
            ServiceReference1.WebService1SoapClient ds = new ServiceReference1.WebService1SoapClient();  //new出WebService对象          
            DateTime dtBegin = DateTime.Now;
            DataSet dataSet = ds.GetDataSet();
            this.label1.Text = string.Format("耗时：{0}", DateTime.Now - dtBegin);
            binddata(dataSet);
        }

        protected void button3_Click(object sender, EventArgs e)
        {
            ServiceReference1.WebService1SoapClient ds = new ServiceReference1.WebService1SoapClient();
            DateTime dtBegin = DateTime.Now;
            byte[] buffer = ds.GetDataSetBytes();
            BinaryFormatter ser = new BinaryFormatter();
            DataSet dataSet = ser.Deserialize(new MemoryStream(buffer)) as DataSet;
            this.label2.Text = string.Format("耗时：{0}", DateTime.Now - dtBegin) + "  " + buffer.Length;
            binddata(dataSet);
        }
        private void binddata(DataSet dataSet)
        {
            this.dataGridView1.DataSource = dataSet.Tables[0];
            this.label5.Text = "共计：" + dataSet.Tables[0].Rows.Count + "条记录";
        }
    }
}